home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Source.bin / ZOrderUtils.java < prev   
Text File  |  1998-08-21  |  4KB  |  128 lines

  1. package symantec.itools.util;
  2.  
  3. import java.awt.Container;
  4. import java.awt.Component;
  5.  
  6. //    07/19/97    RKM    Created this class
  7. //    07/20/97    RKM    Changes to make the boolean calculated
  8. //    08/01/97    RKM    Added assumeZOrder function
  9. //    09/20/97    RKM Updated to new zorder for MRJ 2.0
  10. //    11/05/97    LAB Fixed assumeZOrder such that is behaves as the comments suggest.
  11. //                    (Addresses Mac Bug #9990)
  12.  
  13. /**
  14.  * Determines the order components are drawn: first-to-last or last-to-first.
  15.  */
  16. public final class ZOrderUtils
  17. {
  18.     /**
  19.      * All-static class, do not use.
  20.      */
  21.     private ZOrderUtils() {
  22.     }
  23.  
  24.     /**
  25.      * Determines if the first component is drawn over the second componnet.
  26.      */
  27.     public static boolean isFirstDrawnOverSecond()
  28.     {
  29.         return m_IsFirstDrawnOverSecond;
  30.     }
  31.  
  32.     /**
  33.      * Determines if the second component is drawn over the first componnet.
  34.      */
  35.     public static boolean isSecondDrawnOverFirst()
  36.     {
  37.         return !m_IsFirstDrawnOverSecond;
  38.     }
  39.  
  40.     /**
  41.      * Reverses the order of all components in a container.
  42.      * @param container the container with the components to reverse
  43.      */
  44.     public static void reverseContainersZOrder(Container container)
  45.     {
  46.         //Get a list of the current components in the container
  47.         Component[] components = container.getComponents();
  48.  
  49.         //Remove all of the components
  50.         container.removeAll();
  51.  
  52.         //Reverse the order the components are in
  53.         int numComponents = components.length;
  54.         for (int i = components.length - 1;i >= 0;i--)
  55.         {
  56.             Component component = components[i];
  57.  
  58.             container.add(component);
  59.  
  60.             //???RKM??? What's faster, instanceof and cast or catching ClassCastException???
  61.             if (component instanceof Container)
  62.                 reverseContainersZOrder((Container)component);
  63.         }
  64.     }
  65.  
  66.     /**
  67.      * Reverses the order of all components in a container if the current environment
  68.      * doesn't draw them as assumed.
  69.      * @param container the container with the components to reverse, as needed
  70.      * @param assumedFirstDrawnOverSecond the assumed drawing order. If the actual
  71.      * drawing order matches this, then no component reversal is needed
  72.      */
  73.     public static boolean assumeZOrder
  74.             (Container    container,
  75.              boolean    assumedFirstDrawnOverSecond)
  76.     {
  77.         if (assumedFirstDrawnOverSecond == isFirstDrawnOverSecond())
  78.             return false;
  79.  
  80.         reverseContainersZOrder(container);
  81.  
  82.         return true;
  83.     }
  84.  
  85.     static private boolean m_IsFirstDrawnOverSecond;
  86.  
  87.     static
  88.     {
  89.         String OSName = System.getProperty("os.name");
  90.  
  91.         //???RKM??? We should verify and move these into the OS class
  92.         if (OSName.startsWith("S") ||      // SunOS, Solaris
  93.             OSName.startsWith("Kona") ||   // Kona (Mr. Coffee)
  94.             OSName.startsWith("AIX") ||    // AIX
  95.             OSName.startsWith("OSF") )     // OSF
  96.         {
  97.             m_IsFirstDrawnOverSecond = true;
  98.         }
  99.         else
  100.         {
  101.             String javaVendor = System.getProperty("java.vendor");
  102.             
  103.             boolean javaVendorIsNetscape = javaVendor.startsWith("Netscape");
  104.             
  105.             String javaVersion = System.getProperty("java.version");
  106.             
  107.             // Windows Netscape 3.0bx
  108.             if (symantec.itools.lang.OS.isWindows() &&
  109.                 javaVendorIsNetscape && javaVersion.equals("1.02") )
  110.             {
  111.                 m_IsFirstDrawnOverSecond = true;
  112.             }
  113.             else
  114.             {
  115.                 if (symantec.itools.lang.OS.isMacintosh() &&
  116.                     (javaVendorIsNetscape || (javaVendor.startsWith("Apple") && !javaVersion.equals("1.02"))))
  117.                 {
  118.                     m_IsFirstDrawnOverSecond = true;
  119.                 }
  120.                 else
  121.                 {
  122.                     m_IsFirstDrawnOverSecond = false;
  123.                 }
  124.             }
  125.         }
  126.     }
  127. }
  128.